import 'package:logger/logger.dart';

/// logger 类型
enum LoggerType { trace, debug, info, warning, error, fatal }

class LoggerUtil {
  static final Logger logger = Logger(
    printer: PrettyPrinter(
      methodCount: 0,
      colors: true,
      printEmojis: false,
    ),
  );

  /// 写log
  static void loggerWithType(
    dynamic message, {
    LoggerType type = LoggerType.debug,
  }) {
    switch (type) {
      case LoggerType.trace:
        logger.t(message);
        break;
      case LoggerType.debug:
        logger.d(message);
        break;
      case LoggerType.info:
        logger.i(message);
        break;
      case LoggerType.warning:
        logger.w(message);
        break;
      case LoggerType.error:
        logger.e(message);
        break;
      case LoggerType.fatal:
        logger.f(message);
        break;
      default:
        logger.d(message);
    }
  }
}

/// 模仿print，给出一个全局函数，方便调用
void log(dynamic message, {LoggerType type = LoggerType.info}) {
  LoggerUtil.loggerWithType(message, type: type);
}
